<template>
  <div class="article-item">
    <van-cell class="article-van-cell">
      <!-- 文章标题，使用插槽，原生组件宽度有限制，导致标题换行 -->
      <div class="title van-multi-ellipsis--l2" slot="title">
        {{ article.title }}
      </div>
      <!-- slot="label" 自定义标题下方的内容 -->
      <div slot="label">
        <!-- 有3张封面的文章，封面显示在标题正下方，横向排列 -->
        <div class="cover" v-if="article.cover.type === 3">
          <div
            class="cover-img"
            v-for="(img, index) in article.cover.images"
            :key="index"
          >
            <van-image class="cover-img-item" fit="cover" :src="img" />
          </div>
        </div>
        <!-- 标题最下方内容 -->
        <div class="article-bottom">
          <span>{{ article.aut_name }}</span>
          <span>{{ article.comm_count }}评论</span>
          <span>{{ article.pubdate | relativeTime }}</span>
        </div>
      </div>
      <!-- 使用右侧插槽，只有一张封面的文章，封面显示在右侧 solt="default":右侧插槽 -->
      <van-image
        v-if="article.cover.type === 1"
        slot="default"
        fit="cover"
        :src="article.cover.images[0]"
      />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'ArticleItem',
  props: {
    article: {
      type: Object,
      required: true
    }
  }
}
</script>

<style lang="less" scoped>
.article-van-cell {
  .title {
    font-size: 32px;
    color: #3a3a3a;
  }
  .van-cell__value {
    flex: unset;
    width: 232px;
    height: 146px;
  }
}
// 清除浮动（万能）
.cover {
  // content: "";
  // display: block;
  // height: 0;
  // clear: both;
  // visibility: hidden;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  .cover-img {
    //每一项都平分主轴宽度
    flex: 1;
    height: 146px;
    padding: 30px 0;
    // 父元素的子元素，不包括最后一个子元素
    &:not(:last-child) {
      padding-right: 4px;
    }
    .cover-img-item {
      width: 100%;
      height: 146px;
    }
  }
}
.article-bottom {
  text-align: left;
  bottom: 0;
  span {
    font-size: 22px;
    margin-right: 25px;
    color: #b4b4b4;
    bottom: 0;
  }
}
</style>
